cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)

include(${CMAKE_CURRENT_SOURCE_DIR}/../../../mkspecs/cmake/global.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../mkspecs/cmake/install_lib_qt.cmake)

find_package(Qt5 COMPONENTS Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

file(GLOB_RECURSE SRC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
file(GLOB_RECURSE SRC_CPPS    ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB_RECURSE SRC_UIS     ${CMAKE_CURRENT_SOURCE_DIR}/*.ui)

# qt5_add_resources(QRC ${SOURCES_DIR}/images.qrc)
set(SOURCES ${SRC_HEADERS} ${SRC_CPPS} ${SRC_UIS})
if(WIN32)
    list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/app-qt.rc)
endif()

include_directories(
    ${CYG_INC_PATH}/mod1-shared-ab
    ${CYG_INC_PATH}/mod2-shared-ab
    )

link_libraries(
    Qt5::Widgets 
    debug mod1-shared-ab${CMAKE_DEBUG_POSTFIX} optimized mod1-shared-ab
    debug mod2-shared-ab${CMAKE_DEBUG_POSTFIX} optimized mod2-shared-ab
    )

add_executable(app-qt ${SOURCES})
set_target_properties(app-qt PROPERTIES
    OUTPUT_NAME                   "app-qt"
    DEBUG_OUTPUT_NAME             "app-qt${CMAKE_DEBUG_POSTFIX}"
    VS_DEBUGGER_WORKING_DIRECTORY ${CYG_LIB_PATH})
install(TARGETS app-qt DESTINATION ${INSTALL_RUN_PATH})

install(FILES         app-qt.json                                             DESTINATION ${INSTALL_CONFIG_PATH})
install(FILES         qt.conf                                                 DESTINATION ${INSTALL_RUN_PATH})
if(WIN32)
    install(FILES     app-qt${CMAKE_DEBUG_POSTFIX}.bat                        DESTINATION ${INSTALL_RUN_PATH})
else()
    install(FILES     app-qt${CMAKE_DEBUG_POSTFIX}.sh                         DESTINATION ${INSTALL_RUN_PATH})
    install(FILES     share/applications/app-qt${CMAKE_DEBUG_POSTFIX}.desktop DESTINATION ${INSTALL_DESKTOP_PATH})
    install(DIRECTORY share/icons                                             DESTINATION ${INSTALL_ICONS_PATH})
endif()

# Install Qt librarys
